import 'dart:io';

import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio/dio.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:path_provider/path_provider.dart';
import 'package:qunaimedical/network/interceptors.dart';
import 'package:qunaimedical/values/urls.dart';

class XHttp {
  XHttp._internal();

  static final Dio instance = Dio(BaseOptions(
    baseUrl: Urls.BASE_URL,
    connectTimeout: 5000,
    receiveTimeout: 5000,
  ));

  static late PersistCookieJar cookieJar;

  /// 初始化dio
  static init() async {
    Directory tempDir = await getTemporaryDirectory();
    cookieJar = PersistCookieJar(storage: FileStorage(tempDir.path));
    instance.interceptors.add(CustomInterceptors());
    instance.interceptors.add(CookieManager(cookieJar));
  }
}
